import java.util.ArrayList;


public class convertHeader {

	/*
	 * Converting the array containing the elements of
	 * the header of the heap file into 
	 * arraylist containing type of the each datatype with its length.
	 */
	public static ArrayList<datatype> convertHeader(String columns[])
	{
		//System.out.println("Inside convert");
		ArrayList<datatype> types= new ArrayList<datatype>();
		for(int i = 0; i < columns.length; i++)
		{
			if(columns[i].equalsIgnoreCase("i1"))
			{
				types.add(new datatype(0,1));
				heap.recordlength+=1;
			}

			else if(columns[i].equalsIgnoreCase("i2"))
			{
				types.add(new datatype(1,2));
				heap.recordlength+=2;
			}
			else if(columns[i].equalsIgnoreCase("i4"))
			{
				types.add(new datatype(2,4));
				heap.recordlength+=4;
			}
			else if(columns[i].equalsIgnoreCase("i8"))
			{
				types.add(new datatype(3,8));
				heap.recordlength+=8;
			}
			else if(columns[i].equalsIgnoreCase("r4"))
			{
				types.add(new datatype(4,4));
				heap.recordlength+=4;
			}
			else if(columns[i].equalsIgnoreCase("r8"))
			{
				types.add(new datatype(5,8));
				heap.recordlength+=8;
			}
			else 
			{
				int type = Integer.parseInt(columns[i].substring(1, columns[i].length()));
				types.add(new datatype(6,type));
				heap.recordlength+=type;
			}

		}
		//System.out.println(types.size()+ "types");
		return types;
	}
}
